
require(['./config'], () => {
  require(['header', 'footer', 'cookie'], (header) => {
    class Login {
      constructor() {
        this.loginReady()
      }
      loginReady () {
        $('.dl').on('click', () => {
          let _username = $('.username').val()
          let _password = $('.password').val()
          var userList = localStorage.getItem('userList')
         
          if(userList){
            userList = JSON.parse(userList)
            var isExist = userList.some(userInfo=>{
              return userInfo.username ===_username && userInfo.password===_password
            })
            if(isExist){
              var userInfo={_username,_password}
              $.cookie.raw = true
                let success = $.cookie('userInfo', JSON.stringify(userInfo), { path: '/' })
                if (success) {
                  alert('登录成功，即将跳转到首页')
                  window.location.href = '/index.html'
                }
            }else{
              alert('用户名或密码错误，请重试')
            }
          }else{
            alert('没有用户信息，请先注册，即将跳转到注册页面')
            window.location.href = '/html/regist.html'
          }
        })
      }
    }
    new Login()
  })
})